import { login } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: ''
  },
  mutations: {
    // 设置token
    setToken(state, token) {
      state.token = token // 设置token
    },
    // 删除token
    removeToken(state) {
      state.token = '' // 删除vuex的token
    }
  },
  actions: {
    async userLogin(context) {
      const { data: res } = await login(this.loginForm)
      console.log('获取到的token是', res.data)
      context.commit('setToken', res.data)
    }
  }
}
